package com.ymatou.iapi.notify.testcase;

import com.ymatou.iapi.notify.parameter.SendNotifyBean;
import com.ymatou.iapi.notify.parameter.SetMessageReadByMsgIdBean;
import com.ymatou.iapi.notify.service.SetMessageReadByMsgIdCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.NotifyCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.List;
import java.util.Map;

/**
*设置通知已读
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetMessageReadByMsgId{
	private static SetMessageReadByMsgIdBean setmessagereadbymsgidBean;
	private static SetMessageReadByMsgIdCall setmessagereadbymsgidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置通知已读");
	}

	@Before
	public void caseUp() {
		setmessagereadbymsgidBean=new SetMessageReadByMsgIdBean();
		setmessagereadbymsgidCall=new SetMessageReadByMsgIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setmessagereadbymsgidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMessageReadByMsgId_01() {
		Logger.start(true,"设置通知已读");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			int sendId = 30156393;
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(sendId,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			Map map = new ImDefaultWapper().selectImNotifyByToUserId(userId).get(0);
			Logger.verifyEquals(0,Integer.parseInt(map.get("IsRead").toString()),"验证消息未读");
			String notifyId = map.get("NotifyId").toString();
			String messageId = sendId + "_" + userId + "_" + notifyId;
			Logger.debug(messageId);
			setmessagereadbymsgidBean.setMessageId(messageId);
			setmessagereadbymsgidCall.setData(setmessagereadbymsgidBean);
			setmessagereadbymsgidCall.callService();
			Logger.verifyEquals("Success",setmessagereadbymsgidCall.getString("Status"),"验证Status");
			Map map1 = new ImDefaultWapper().selectImNotifyByToUserId(userId).get(0);
			Logger.verifyEquals(1,Integer.parseInt(map1.get("IsRead").toString()),"验证消息已读");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetMessageReadByMsgId_02() {
		Logger.start(true,"设置通知已读，messageId为空");
		try {
			setmessagereadbymsgidBean.setMessageId(null);
			setmessagereadbymsgidCall.setData(setmessagereadbymsgidBean);
			setmessagereadbymsgidCall.callService();
			Logger.verifyEquals("ParameterError",setmessagereadbymsgidCall.getString("Status"),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}